package com.imessage.jobs;


import com.imessage.service.TaskService;
import com.imessage.service.WumaService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Calendar;
import java.util.Date;

@Slf4j
@Component
@Configurable
@EnableScheduling
public class ScheduledTasks {

    @Autowired
    private WumaService wumaService;
    @Autowired
    private TaskService taskService;

    //每小时执行一次
    @Scheduled(cron = "0 0 */1  * * * ")
    public void getPreHourTask() {
        String className = Thread.currentThread().getStackTrace()[1].getClassName();
        String methodName = Thread.currentThread().getStackTrace()[1].getMethodName();
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());
        calendar.add(Calendar.DATE, -1);
    }

    //每1分钟执行一次
    @Scheduled(cron = "0 */1 *  * * * ")
    public void getMinuteTask() {
        String className = Thread.currentThread().getStackTrace()[1].getClassName();
        String methodName = Thread.currentThread().getStackTrace()[1].getMethodName();
        try{
            wumaService.createConfig();
        }catch (Exception e){
            log.error("", e);
        }
    }

    //每天凌晨三点执行一次
    @Scheduled(cron = "0 0 3 * * ? ")
    public void getReportResultTask() {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());
        calendar.add(Calendar.DATE, -1);

    }


}
